<template>
  <div>
    <Breadcrumb></Breadcrumb>
    <el-card>
      <el-row :gutter="24">
        <el-col :span="10">
          <el-input placeholder="请输入内容" class="input-with-select">
            <el-button slot="append" icon="el-icon-search"></el-button>
          </el-input>
        </el-col>
      </el-row>
      <el-table :data="tableData" border style="width: 100%">
        <el-table-column type="index" label="#"></el-table-column>
        <el-table-column prop="order_number" label="订单编号" width="200"></el-table-column>
        <el-table-column prop="order_price" label="订单价格" width="200"></el-table-column>
        <el-table-column label="是否付款" prop="order_pay">
          <template slot-scope="scope">
            <el-tag type="dark" v-if="scope.row.order_pay === '1'" effect="dark">已付款</el-tag>
            <el-tag type="danger" effect="dark" v-else>未付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="is_send" label="是否发货" width="200"></el-table-column>
        <el-table-column label="下单时间" prop="create_time" width="200">
          <template
            slot-scope="scope"
          >{{ scope.row.create_time | dateformat('YYYY-MM-DD HH:mm:ss')}}</template>
        </el-table-column>
        <el-table-column label="操作" width="200">
          <template>
            <el-tooltip class="item" effect="dark" content="修改订单地址" placement="top">
              <el-button type="primary" icon="el-icon-edit" size="mini" @click="show"></el-button>
            </el-tooltip>
            <el-tooltip class="item" effect="dark" content="物流信息" placement="top">
              <el-button
                type="success"
                icon="el-icon-location-outline"
                size="mini"
                @click="showProgress"
              ></el-button>
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页器 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.pagenum"
        :page-sizes="[3, 5, 10, 15]"
        :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
    </el-card>
    <!-- 弹出物流信息 -->
    <!-- 物流信息进度对话框 -->
    <el-dialog title="物流进度" :visible.sync="progressVisible" width="50%">
      <!-- 时间线组件  -->
      <el-timeline>
        <el-timeline-item
          v-for="(activity, index) in progressInfo"
          :key="index"
          :timestamp="activity.time"
        >{{activity.context}}</el-timeline-item>
      </el-timeline>
    </el-dialog>
    <!-- 省市区联动 -->
    <el-dialog title="物流进度" :visible.sync="addressVisible" width="50%">
      <!-- 添加表单 -->
      <el-form
        :model="addressForm"
        :rules="addressFormRules"
        ref="addressFormRef"
        label-width="100px"
      >
        <el-form-item label="省市区县" prop="address1">
          <el-cascader :options="cityData" v-model="addressForm.address1"></el-cascader>
        </el-form-item>
        <el-form-item label="详细地址" prop="address2">
          <el-input v-model="addressForm.address2"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="addressVisible = false">取 消</el-button>
        <el-button type="primary" @click="addressVisible = false">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { getOrdersDataList, getShowPropress } from "@/api/Orders/orders.js";
import Breadcrumb from "@/components/Breadcrumb";
import cityData from "./citydata.js";
import moment from "moment";
export default {
  //import引入的组件需要注入到对象中才能使用
  components: { Breadcrumb },
  props: {},
  data() {
    //这里存放数据
    return {
      //控制修改地址对话框的显示和隐藏
      addressVisible: false,
      //修改收货地址的表单
      addressForm: {
        address1: [],
        address2: ""
      },
      addressFormRules: {
        address1: [
          { required: true, message: "请选择省市区县", trigger: "blur" }
        ],
        address2: [
          { required: true, message: "请输入详细地址", trigger: "blur" }
        ]
      },
      //将导入的cityData数据保存起来
      cityData: cityData,
      tableData: [], //订单列表数据
      queryInfo: {
        query: "",
        pagenum: 1,
        pagesize: 10
      },
      total: 0,
      progressVisible: false,
      progressInfo: [],
      shenVisible: false
    };
  },
  //计算属性 类似于data概念
  computed: {},
  //监控data中的数据变化
  watch: {},
  //方法集合
  methods: {
    async getOrdersData() {
      const { data: res } = await getOrdersDataList(this.queryInfo) 
      console.log(res);
      if (res.meta.msg != "获取成功")
        return this.$message.error("获取订单列表失败");
      this.$message.success("获取订单列表成功");
      this.tableData = res.data.goods;
      this.total = res.data.total;
    },
    //分页器
    handleSizeChange(pagesize) {
      this.queryInfo.pagesize = pagesize;
      this.getOrdersData();
      console.log(`每页 ${pagesize} 条`);
    },
    handleCurrentChange(pagenum) {
      this.queryInfo.pagenum = pagenum;
      this.getOrdersData();
      console.log(`当前页: ${pagenum}`);
    },
    async showProgress() {
      //发送请求获取物流数据
      const { data: res } = await getShowPropress()

      if (res.meta.status !== 200) {
        return this.$message.error("获取物流进度失败!");
      }
      this.progressInfo = res.data;
      //显示对话框
      this.progressVisible = true;
    },
    show() {
      this.addressVisible = true;
    }
  },

  //生命周期 - 创建完成（可以访问当前this实例）
  created() {
    this.getOrdersData();
  },
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {},
  beforeCreate() {}, //生命周期 - 创建之前
  beforeMount() {}, //生命周期 - 挂载之前
  beforeUpdate() {}, //生命周期 - 更新之前
  updated() {}, //生命周期 - 更新之后
  beforeDestroy() {}, //生命周期 - 销毁之前
  destroyed() {}, //生命周期 - 销毁完成
  activated() {} //如果页面有keep-alive缓存功能，这个函数会触发
};
</script>
<style lang='scss' scoped>
.el-card {
  margin-top: 20px;
  background: rgba(0, 0, 0, 0.9);
}
.el-table {
  margin-top: 20px;
  background: rgba(0, 0, 0, 0.9) !important;
}
/deep/.el-table__body-wrapper {
  background: rgba(0, 0, 0, 0.9) !important;
}
.el-pagination {
  margin-top: 20px;
  color: black;
}
</style>
